@extends('admin/index')
@section('name')
    <h1><span class="label label-default"> 新增公告 </span></h1>
    <hr>

    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
      <form class="form-horizontal" action="{{url('adm/ann/add')}}" name="ckname"  onsubmit="return checkForm()">
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">公告内容:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="ann_cont" placeholder="cont" onblur="checkname()">
                            <p id="p" style="display: none">内容不能为空</p>
                        </div>
                    </div>


                    <div class="form-group">
                        <label for="inputPassword3" class="col-sm-2 control-label">Url:</label>
                        <div class="col-sm-10" id="pppw">
                            <input type="text" class="form-control" name="ann_url" onblur="checkurl()">
                            <p id="p1" style="display: none">格式以:http:// 或 https://  xxxx.com</p>
                        </div>
                    </div>


                    <div class="form-group">
                        <label for="inputPassword3" class="col-sm-2 control-label">是否隐藏</label>
                        <div class="col-sm-10">
                            <label class="radio-inline">
                                <input type="radio" name="display" value="0"> no
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="display" value="1" checked> yes
                            </label>
                        </div>
                    </div>


                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-default" id="ti">提交</button>
                        </div>
                    </div>

                </form>
            </div>
        </div>
    </div>


    <script>


        //网址url验证
        function checkurl(){

            var ckname = document.ckname.ann_url.value;
            var p1 = document.getElementById('p1');

            if (ckname.match(/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/) == null ) {



                p1.style.display = 'block';
                p1.style.color = 'red';

                return false;
            }

            p1.style.display = 'none';
            return true ;
        }





        //内容验证
        function checkname() {

            var ckname = document.ckname.ann_cont.value;
            var p = document.getElementById('p');


            if(ckname ==''){
                p.style.display = 'block';
                p.style.color = 'red';

                return false;
            }else{
                p.style.display = 'none';
            }


            return true;

        }




       function checkForm() {

            return checkurl() &&  checkname()
       }



        //当鼠标经过提交按钮时触发 检测
       $('#ti').mouseenter(function(){

           var ck = document.ckname.ann_cont.value;
           var ckname = document.ckname.ann_url.value;

           if(ckname == '' && ck == ''){
               alert('请填写数据');
           }

       })




    </script>





@endsection
